package com.main.mail;

import java.io.File;
import java.util.Properties;

import javax.mail.internet.MimeMessage;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;

import junit.framework.TestCase;

public class TestMail {
	
	public static void main(String[] args) {
		try{
			JavaMailSenderImpl sender = new JavaMailSenderImpl();
			sender.setHost("smtp.zoho.com");
			sender.setPort(465);
//			sender.setUsername("tbofju@gmail.com");
//			sender.setPassword("Dimleon13");
//			
//			Properties mailProperties = new Properties();
//			mailProperties.setProperty("mail.smtp.socketFactory.class",
//					"javax.net.ssl.SSLSocketFactory");
//			mailProperties.setProperty("mail.smtp.socketFactory.port", "465");
//			mailProperties.setProperty("mail.smtp.auth", "true");
//			mailProperties.setProperty("mail.smtp.auth", "true");
//			mailProperties.setProperty("mail.smtp.starttls.enable", "true");
			
			sender.setUsername("alfinte@zoho.com");
			sender.setPassword("alfinte123");
			
			Properties mailProperties = new Properties();
//			mailProperties.put("mail.smtp.host", "smtp.zoho.com");
//			mailProperties.put("mail.smtp.socketFactory.port", "465");
			mailProperties.put("mail.smtp.socketFactory.class",
					"javax.net.ssl.SSLSocketFactory");
			mailProperties.put("mail.smtp.auth", "true");
//			mailProperties.put("mail.smtp.port", "465");
			
			sender.setJavaMailProperties(mailProperties);
			
			sender.send(new MimeMessagePreparator() {
				@Override
				public void prepare(MimeMessage mimeMessage) throws Exception {
					MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
					mimeMessageHelper.setFrom("alfinte@zoho.com", "No replay");
					mimeMessageHelper.setTo(new String[]{"tbofju@gmail.com"});
					mimeMessageHelper.setSubject("TEST");
					mimeMessageHelper.setText("<style>.bold{font-weight: bold;}</style><div class='bold'>HOLA</div>", true);
				}
			});
			System.out.println("Done");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
